from pyeasyaccept.commom.Configuration import Configuration
from pyeasyaccept.PythonEasyAcceptFacade import PythonEasyAcceptFacade
from pythoneasyaccept_test.TestFacade import TestFacade
import unittest

"""
This class tests the PythonEasyAcceptFacade
@author: Mikaela Maia
"""
class PythonEasyAcceptFacadeTest3(unittest.TestCase):

    def setUp(self):
        self.FILE_SEPARATOR = Configuration.FILE_SEPARATOR  
        self.testFacade = TestFacade()
        self.configuration = Configuration()        
        self.root = self.configuration.getProjectRoot()
            
    def tearDown(self):
        pass
    
    """
    This test method tests the PythonEasyAccept API method - maxErrorsToReport
    """
    def testMaxErrorsToReport(self):
        
        scriptFile1 = self.root + self.configuration.TEST_SCRIPTS_LOCATION + self.FILE_SEPARATOR +"script01.txt"
        scriptFile2 = self.root + self.configuration.TEST_SCRIPTS_LOCATION + self.FILE_SEPARATOR + "script02.txt"
        scriptFile3 = self.root + self.configuration.ACCEPTANCE_TEST_SCRIPTS_LOCATION + self.FILE_SEPARATOR + "test1.txt"
        scriptFile4 = self.root + self.configuration.ACCEPTANCE_TEST_SCRIPTS_LOCATION + self.FILE_SEPARATOR + "testError3.txt"
        scriptFile5 = self.root + self.configuration.ACCEPTANCE_TEST_SCRIPTS_LOCATION + self.FILE_SEPARATOR + "testError1.txt"
        scriptFile6 = self.root + self.configuration.ACCEPTANCE_TEST_SCRIPTS_LOCATION + self.FILE_SEPARATOR + "testError4.txt"
#          script: all right
        file = [scriptFile3]
        facade = PythonEasyAcceptFacade(self.testFacade, file);
        facade.maxErrorsToReport(0);
        facade.executeTests()
        self.assertEquals(6 , facade.getTotalNumberOfTests())
        
        facade8 = PythonEasyAcceptFacade(self.testFacade, file);
        facade8.maxErrorsToReport(2);
        facade8.executeTests()
        self.assertEquals(6 , facade8.getTotalNumberOfTests())
        
        #script: 2 wrongs, 2 rights, 1 wrong
        file3 = [scriptFile4]
        facade3 = PythonEasyAcceptFacade(self.testFacade, file3);
        facade3.maxErrorsToReport(2);
        facade3.executeTests()
        self.assertEquals(2 , facade3.getTotalNumberOfTests())

        facade4 = PythonEasyAcceptFacade(self.testFacade, file3);
        facade4.maxErrorsToReport(3);
        facade4.executeTests()
        self.assertEquals(5 , facade4.getTotalNumberOfTests())
        
        facade9 = PythonEasyAcceptFacade(self.testFacade, file3);
        facade9.maxErrorsToReport(0);
        facade9.executeTests()
        self.assertEquals(0 , facade9.getTotalNumberOfTests())
        
#         script:1 wrong 
        file5 = [scriptFile5]
        facade5 = PythonEasyAcceptFacade(self.testFacade, file5)
        facade5.maxErrorsToReport(0)
        facade5.executeTests()
        self.assertEquals(0 , facade5.getTotalNumberOfTests())
        
        facade2 = PythonEasyAcceptFacade(self.testFacade, file5)
        facade2.maxErrorsToReport(1)
        facade2.executeTests()
        self.assertEquals(1 , facade2.getTotalNumberOfTests())
        
#        script: right, wrong, right, wrong, right
        file6 = [scriptFile6]
        facade6 = PythonEasyAcceptFacade(self.testFacade, file6);
        facade6.maxErrorsToReport(0);
        facade6.executeTests()
        self.assertEquals(1 , facade6.getTotalNumberOfTests())
        
        facade7 = PythonEasyAcceptFacade(self.testFacade, file6);
        facade7.maxErrorsToReport(2);
        facade7.executeTests()
        self.assertEquals(4 , facade7.getTotalNumberOfTests())
        
if __name__ == '__main__':
    unittest.main()